import Mock from 'mockjs'
import users from './users'
import timelog from './timelog'
import * as utils from '../utils'

// 模拟数据
Mock.mock('/api/data', 'get', () => {
  console.log('mock')
  return {
    list: Mock.mock({
      'items|10': [{ // 生成10个列表项
        id: '@increment',
        name: '@name',
        date: '@date'
      }]
    })
  }
})

Mock.mock('/api/login', 'post', (req) => {
  const body = JSON.parse(req.body)
  const username = body.username
  const password = body.password
  const item = users.find((user) => { return user.username === username && user.password === password })

  if (item) {
    return {
      code: 200,
      message: '登录成功',
      data: item
    }
  } else {
    return {
      code: 201,
      message: '登录失败',
      data: null
    }
  }
})

Mock.mock('/api/users', 'get', () => {
  return {
    code: 200,
    message: '获取用户列表成功',
    data: users
  }
})

Mock.mock('/api/timelog', 'get', () => {
  return {
    code: 200,
    message: '获取时间日志列表成功',
    data: timelog
  }
})

Mock.mock('/api/projects', 'get', () => {
  return {
    code: 200,
    message: '获取项目列表成功',
    data: [
      { id: 1, name: 'Projact-Freja 芙蕾雅' },
      { id: 2, name: 'Project-Cube四方动物城' },
      { id: 3, name: 'Downtime其他' },
    ]
  }
})

Mock.mock('/api/timelogbyteam', 'get', () => {
  return {
    code: 200,
    message: '获取日志列表成功',
    data: [
      {
        id: 1,
        name: '张三',
        rowOccupy: 3,
        time: '8:00-9:00',
        '2024-9-1_project': 1,
        '2024-9-1_Statement': '1 任务说明',
        '2024-9-2_project': 2,
        '2024-9-2_Statement': '2 任务说明',
        '2024-9-3_project': 1,
        '2024-9-3_Statement': '3 任务说明',
      },
      {
        id: 2,
        name: '张三',
        rowOccupy: 3,
        time: '9:00-10:00',
        '2024-9-1_project': 2,
        '2024-9-1_Statement': '1 任务说明',
        '2024-9-2_project': 1,
        '2024-9-2_Statement': '2 任务说明',
        '2024-9-3_project': 3,
        '2024-9-3_Statement': '3 任务说明',
      },
      {
        id: 3,
        name: '张三',
        rowOccupy: 3,
        time: '10:00-11:00',
        '2024-9-1_project': 1,
        '2024-9-1_Statement': '1 任务说明',
        '2024-9-2_project': 2,
        '2024-9-2_Statement': '2 任务说明',
        '2024-9-3_project': 3,
        '2024-9-3_Statement': '3 任务说明',
      },
      {
        id: 11,
        name: '李四',
        rowOccupy: 3,
        time: '8:00-9:00',
        '2024-9-1_project': 1,
        '2024-9-1_Statement': '1 任务说明',
        '2024-9-2_project': 2,
        '2024-9-2_Statement': '2 任务说明',
        '2024-9-3_project': 1,
        '2024-9-3_Statement': '3 任务说明',
      },
      {
        id: 12,
        name: '李四',
        rowOccupy: 3,
        time: '9:00-10:00',
        '2024-9-1_project': 2,
        '2024-9-1_Statement': '1 任务说明',
        '2024-9-2_project': 1,
        '2024-9-2_Statement': '2 任务说明',
        '2024-9-3_project': 3,
        '2024-9-3_Statement': '3 任务说明',
      },
      {
        id: 13,
        name: '李四',
        rowOccupy: 3,
        time: '10:00-11:00',
        '2024-9-1_project': 1,
        '2024-9-1_Statement': '1 任务说明',
        '2024-9-2_project': 2,
        '2024-9-2_Statement': '2 任务说明',
        '2024-9-3_project': 3,
        '2024-9-3_Statement': '3 任务说明',
      },
      {
        id: 21,
        name: '王五',
        rowOccupy: 4,
        time: '8:00-9:00',
        '2024-9-1_project': 1,
        '2024-9-1_Statement': '1 任务说明',
        '2024-9-2_project': 2,
        '2024-9-2_Statement': '2 任务说明',
        '2024-9-3_project': 1,
        '2024-9-3_Statement': '3 任务说明',
      },
      {
        id: 22,
        name: '王五',
        rowOccupy: 4,
        time: '9:00-10:00',
        '2024-9-1_project': 2,
        '2024-9-1_Statement': '1 任务说明',
        '2024-9-2_project': 1,
        '2024-9-2_Statement': '2 任务说明',
        '2024-9-3_project': 3,
        '2024-9-3_Statement': '3 任务说明',
      },
      {
        id: 23,
        name: '王五',
        rowOccupy: 4,
        time: '10:00-11:00',
        '2024-9-1_project': 1,
        '2024-9-1_Statement': '1 任务说明',
        '2024-9-2_project': 2,
        '2024-9-2_Statement': '2 任务说明',
        '2024-9-3_project': 3,
        '2024-9-3_Statement': '3 任务说明',
      },
      {
        id: 24,
        name: '王五',
        rowOccupy: 4,
        time: '11:00-12:00',
        '2024-9-1_project': 1,
        '2024-9-1_Statement': '1 任务说明',
        '2024-9-2_project': 2,
        '2024-9-2_Statement': '2 任务说明',
        '2024-9-3_project': 3,
        '2024-9-3_Statement': '3 任务说明',
      },
      {
        id: 31,
        name: '薛六',
        rowOccupy: 1,
        time: '11:00-12:00',
        '2024-9-1_project': 1,
        '2024-9-1_Statement': '1 任务说明',
        '2024-9-2_project': 2,
        '2024-9-2_Statement': '2 任务说明',
        '2024-9-3_project': 3,
        '2024-9-3_Statement': '3 任务说明',
      },

      {
        id: 41,
        name: '赵七',
        rowOccupy: 2,
        time: '11:00-12:00',
        '2024-9-1_project': 1,
        '2024-9-1_Statement': '1 任务说明',
        '2024-9-2_project': 2,
        '2024-9-2_Statement': '2 任务说明',
        '2024-9-3_project': 3,
        '2024-9-3_Statement': '3 任务说明',
      },
      {
        id: 42,
        name: '赵七',
        rowOccupy: 2,
        time: '11:00-12:00',
        '2024-9-1_project': 1,
        '2024-9-1_Statement': '1 任务说明',
        '2024-9-2_project': 2,
        '2024-9-2_Statement': '2 任务说明',
        '2024-9-3_project': 3,
        '2024-9-3_Statement': '3 任务说明',
      },
      {
        id: 51,
        name: '李八',
        rowOccupy: 2,
        time: '11:00-12:00',
        '2024-9-1_project': 1,
        '2024-9-1_Statement': '1 任务说明',
        '2024-9-2_project': 2,
        '2024-9-2_Statement': '2 任务说明',
        '2024-9-3_project': 3,
        '2024-9-3_Statement': '3 任务说明',
      },
    ]
  }
})

Mock.mock('/api/requirement-statistics', 'get', () => {
  const deptList = [{ "deptId": 103, "deptName": "研发部门" }, { "deptId": 201, "deptName": "资产组" }, { "deptId": 104, "deptName": "市场部门" }, { "deptId": 202, "deptName": "合成组" }, { "deptId": 105, "deptName": "测试部门" }, { "deptId": 200, "deptName": "动画" }, { "deptId": 203, "deptName": "剪辑组" }, { "deptId": 106, "deptName": "财务部门" }, { "deptId": 204, "deptName": "鏡頭解算组" }, { "deptId": 107, "deptName": "运维部门" }, { "deptId": 205, "deptName": "dpr組" }, { "deptId": 206, "deptName": "資產角色解算组" }, { "deptId": 207, "deptName": "肌肉組" }, { "deptId": 208, "deptName": "动捕组" }, { "deptId": 209, "deptName": "動畫預覽組" }, { "deptId": 210, "deptName": "AE组" }, { "deptId": 211, "deptName": "鏡頭-返修组" }, { "deptId": 212, "deptName": "鏡頭跟踪組" }, { "deptId": 213, "deptName": "扫描组" }, { "deptId": 214, "deptName": "鏡頭肌肉组" }, { "deptId": 215, "deptName": "ue组" }, { "deptId": 216, "deptName": "办公室组" }, { "deptId": 217, "deptName": "SAS组" }, { "deptId": 218, "deptName": "材质组" }, { "deptId": 219, "deptName": "前期组" }, { "deptId": 220, "deptName": "技术组" }, { "deptId": 221, "deptName": "绑定组" }, { "deptId": 222, "deptName": "PA组" }, { "deptId": 223, "deptName": "灯光组" }, { "deptId": 224, "deptName": "模型组" }, { "deptId": 225, "deptName": "特效组" }, { "deptId": 226, "deptName": "动画组" }, { "deptId": 227, "deptName": "二維特效組" }]
  const startDate = new Date('2024-09-29');
  const endDate = new Date('2024-11-02');
  const weeks = utils.getWeeksBetweenDates(startDate, endDate)

  const data = []
  for (let index = 0; index < deptList.length; index++) {
    const element = deptList[index];
    for (let idx2 = 0; idx2 < weeks.length; idx2++) {
      const { start, end } = weeks[idx2];
      data.push({
        ...element, weekStartDate: utils.formatDate(start, 'yyyy-MM-dd'), weekEndDate: utils.formatDate(end, 'yyyy-MM-dd'),
        durationTime: Mock.Random.natural(10000, 20000),
      })
    }
  }

  return {
    code: 200,
    msg: '获取成功',
    rows: data
  }
})

Mock.mock('/api/error-message', 'get', () => {
  return {
    code: 500,
    msg: '过期',
  }
})

Mock.mock('/api/oa/asset/listall', 'get', () => {
  const rs = Mock.mock({
    'rows|30': [{
      id: '@increment',
      name: '@title(5)',
      "createBy": "",
      createTime: '@date("yyyy-MM-dd HH:mm:ss")',
      "updateBy": "",
      updateTime: '@date("yyyy-MM-dd HH:mm:ss")',
      remark: '@cword(10)',
      code: '@word(5)',
      assetCategory: '@integer(101, 999)',
      userId: '@integer(101, 999)',
      userName: '@name',
      userNick: '@cname',
      deptId: '@integer(101, 999)',
      deptName: '@ctitle',
      assetStatus: '@integer(0, 1)'
    }]
  })
  return {
    "total": 1,
    "code": 200,
    "msg": "查询成功",
    rows: rs.rows
  }
})